#!/bin/bash

# 下载功能测试脚本

echo "开始测试下载功能..."

# 启动服务
echo "启动导航服务..."
./navigation-service &
SERVICE_PID=$!

# 等待服务启动
echo "等待服务启动..."
sleep 3

# 测试下载页面
echo "测试下载页面..."
curl -s -o /dev/null -w "下载页面状态码: %{http_code}\n" http://localhost:8080/download

# 测试文件检查API
echo "测试文件检查API..."
echo "macOS ARM64:"
curl -s http://localhost:8080/api/download/check/macos-arm64 | python3 -m json.tool 2>/dev/null || echo "JSON解析失败"

echo "Windows AMD64:"
curl -s http://localhost:8080/api/download/check/windows-amd64 | python3 -m json.tool 2>/dev/null || echo "JSON解析失败"

echo "Linux AMD64:"
curl -s http://localhost:8080/api/download/check/linux-amd64 | python3 -m json.tool 2>/dev/null || echo "JSON解析失败"

# 测试文件下载（只下载前100字节）
echo "测试文件下载..."
echo "macOS ARM64 文件头:"
curl -s -r 0-99 http://localhost:8080/api/download/macos-arm64 | wc -c

echo "Windows AMD64 文件头:"
curl -s -r 0-99 http://localhost:8080/api/download/windows-amd64 | wc -c

# 停止服务
echo "停止服务..."
kill $SERVICE_PID 2>/dev/null

echo "测试完成！"
